﻿using UnityEngine;
using System.Collections;
using Controller;

public class HUDViewModel {
    private PrCharacterController prcController;	
	private GameMenu gmMenu;
	private SubMenu sbMenu;
	private ChangedHud _chHud;
	private UIToolkit _utFont;
    private UIToolkit _utItems;
	private UIToolkit _tkMenu;
    public ChangedHud _chHUD;
    public Animation _animation;
	public ChangedHud ChHUD
	{
		get { return _chHud; }
		set	{ _chHud = value; }
	}
	
	public UIToolkit UtFont
	{
		get {return _utFont;}
		set{ _utFont = value ;}
	}
	
	public UIToolkit TkMenu
	{
		get {return _tkMenu;}
		set{ _tkMenu = value ;}
	}
    public UIToolkit TkItems
    {
        get { return _utItems; }
        set { _utItems = value; }
    }

    private PrCharacterController GetPrcController()
    {
        if (prcController == null)
            prcController = new PrCharacterController();
        return prcController;
    }

	public void CallSubMenu(UIButton sender)
	{
		ChHUD.UpdateHUD();
	}
	
	public void OpenAndCloseSubMenu(UIButton sender)
	{
		if(gmMenu == null)
		{
			gmMenu = new GameMenu(TkMenu);
			gmMenu.Show();
		}
		if(!gmMenu.GetStateShow())
			gmMenu.Show();
	}
	
	public void ChangeText()
	{
		ScreenGeneral.Neko.GetMoney(10);
	}
	
	public void OpenAndCloseInventory(UIButton sender)
	{
		if(sbMenu == null){
			sbMenu = new SubMenu();
			sbMenu.UiFont = UtFont;
            sbMenu.UiItems = TkItems;
			sbMenu.InitializeControls();
            sbMenu._chHUD = this._chHUD;
			sbMenu.Hide();
		}
		if(sbMenu.GetStateShow())
			sbMenu.Show();
		else
			sbMenu.Hide();
	}
	
	public void DoAction(UIButton sender)
	{
		switch(ScreenGeneral.Neko.Action)
		{
			case EnumTypes.CharactherAction.PickUp:
                if (ScreenGeneral.CanPickUp)
                {
                    if (ScreenGeneral.CollisionElement != null)
                    {
                        _animation.Play("PickUp");
                        GetPrcController().PickUpItem();
                        _animation.Play("Idle");
                    }
                }
                else
                {
                    ScreenGeneral.message = "Debe seleccionar una bolsa para recoger";
                }
				break;
			case EnumTypes.CharactherAction.Talk:
                ScreenGeneral.StartTalk = !ScreenGeneral.StartTalk;
				Debug.Log("Start Talk");
				break;
			case EnumTypes.CharactherAction.Walk:
				Debug.Log("Walk");
				break;
		}
	}
}
